package GUI.lecturerGUI;

import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.annotation.Documented;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import controllers.LecturerController;
import entities.ExtractedExam;

import GUI.MainGUI;

/**
 * @category This class handles reportsGUI of lecturer 
 * 
 *
 *
 *
 * @author Omri Barda		039725890
 * @author Amit Joseph		034608547
 * @author Gilad Shpigel  	300162393
 * @author Elad Elbaz		040539959
 * @version May 2012
 */


@SuppressWarnings("serial")
public class LecturerReports extends JPanel  implements ActionListener{
	
	private LecturerController lecturerCtrl;
	public LecturerReports(LecturerController lecturerCtrl) {
		
		super();
		initialize();
		this.lecturerCtrl = lecturerCtrl;
				}
	private JButton btnGetReport;
	private JLabel lblChooseReport;
	private	JComboBox cmbBxreports;
	private JButton btnMainMenu;
	private	JButton btnExit;
	private ArrayList<ExtractedExam> examLst;
	
		private void initialize() {
			setBorder(new TitledBorder(null, "Lecturer  Reports: ", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			setBackground(SystemColor.activeCaption);
			setBounds(0,0,MainGUI.setX,MainGUI.setY);
			setLayout(null);	
			
			add(GETbtnGetReport());
			add(GETlblChooseReport());
			add(GETcmbBxreports());
			add(GETbtnNainMenu());
			add(GETbtnExit());
		}
			

		private JButton GETbtnGetReport()
		{
			if(btnGetReport==null)
				{
					btnGetReport = new JButton("Get report");
					btnGetReport.setBounds(10, 449, 111, 40);
					btnGetReport.addActionListener(this);
					btnGetReport.setEnabled(false);
				}
			return btnGetReport;
		}
			
		private JLabel GETlblChooseReport()
		{
			if(lblChooseReport==null)
				{
					lblChooseReport = new JLabel("Choose exam : ");
					lblChooseReport.setFont(new Font("David", Font.PLAIN, 14));
					lblChooseReport.setBounds(36, 66, 128, 23);
				}
			return lblChooseReport;
		}
			
		private JComboBox GETcmbBxreports()
		{
			if (cmbBxreports==null)
			{
				cmbBxreports = new JComboBox();
				cmbBxreports.setToolTipText("exam number");
				cmbBxreports.setBounds(49, 100, 408, 20);
				cmbBxreports.addActionListener(this);
			}
			return cmbBxreports;
		}

		private JButton GETbtnNainMenu()
		{
			if (btnMainMenu==null)
				{
				btnMainMenu = new JButton("Main Menu");
				btnMainMenu.addActionListener(this);
				btnMainMenu.setBounds(370, 466, 111, 23);				
				}
			return btnMainMenu;
		}

		private JButton GETbtnExit()
		{
			if (btnExit==null)
				{
					btnExit = new JButton("EXIT");
					btnExit.setBounds(271, 466, 89, 23);
					btnExit.addActionListener(this);
				}
			return btnExit;
		}
		
		
		public ExtractedExam getExamCode(){
			int temp = cmbBxreports.getSelectedIndex();
		return  examLst.get(temp);
		}
		/**
		 * 	add exam to reports combo
		 * @param exm - 
		 */

		public void addReport(ArrayList<ExtractedExam> exm) {
			examLst=new ArrayList<ExtractedExam>();
			examLst.addAll(0, exm);
			cmbBxreports.removeAllItems();
			for (int i = 0; i < (exm.size()); i++)
				cmbBxreports.addItem("EXAMCODE:" + examLst.get(i).getExamCode());// + // examLst.get(i).getCourseID()+ examLst.get(i).getSubjectID());
			cmbBxreports.addActionListener(this);
		}
		
		
		@Override
		/*
		 *  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		public void actionPerformed(ActionEvent e) {
			
			
			if(e.getSource() == cmbBxreports){
				if (cmbBxreports.getSelectedIndex() >-1)
					btnGetReport.setEnabled(true);
			}
			
			if(e.getSource() == btnMainMenu){
				lecturerCtrl.handleLectutereGUI(LecturerController.MAIN);
				
			}
			if(e.getSource() == btnExit){

				lecturerCtrl.handleLectutereGUI(LecturerController.EXIT);
				}
			if(e.getSource() == btnGetReport){
				lecturerCtrl.GetReportFile(getExamCode());
				//lecturerCtrl.handleLectutereGUI(LecturerController.REPORTFILE);
			
		
			}

			}

		}	


